Changing Enumerated Values

I have an enumerated Attribute called Test with the following values of "x, y, z, a, b, c" (just an example) Is there an easy way via DXL script to change "y" to "d"? I don't want to have to do it manually in our 25+ modules.

Regards
vppatel - Mon Sep 19 15:03:24 EDT 2011

Re: Changing Enumerated Values
SystemAdmin - Mon Sep 19 17:07:08 EDT 2011

See these threads on how to modify an enumerated type.

https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14676701&#14676701
https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14657662&#14657662

you want to build 4 arrays. the first array contains the string values you want to put into the type. You will also need the value associated with the each entry. The next array is the color mapping (i always set the color mapping to -1, which essentially means you dont care about it). Finally, you need the mapping to the previous type. This array contains the index of the entry in the previous type and -1 if it is a new value. This one can get tricky and is discussed in more detail in the referenced posts. For your example the arrays would look like this.
 

string stringVals[] = ["x", "d", "z", "a", "b", "c"] 
int ordinals[] = [0, 1, 2, 3, 4, 5]
int colors[] = [-1, -1, -1, -1, -1, -1]
int mapping[] = [0, -1, 2, 3, 4, 5]

 


once you have these arrays built, you call the modify command. The whole picture would look something like this

AttrType at = find(Module mod, string typeName)
if (null at) {
    // type not found
}
string errMsg = null
 
string stringVals[] = ["x", "d", "z", "a", "b", "c"] 
int ordinals[] = [0, 1, 2, 3, 4, 5]
int colors[] = [-1, -1, -1, -1, -1, -1]
int mapping[] = [0, -1, 2, 3, 4, 5]
 
 
at = modify(at, typeName, stringVals, ordinals, colors, mapping, errMsg)
 
// if there was an error with the modify, print the message
if (!null errMsg){
    print errMsg"\n"
}



I didnt have time to really check it or look too much up so a second check on this (cough louie) would be nice.
Hope this helps,

-Adam



 

Re: Changing Enumerated Values
llandale - Mon Sep 19 17:22:42 EDT 2011

SystemAdmin - Mon Sep 19 17:07:08 EDT 2011

See these threads on how to modify an enumerated type.

https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14676701&#14676701
https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14657662&#14657662

you want to build 4 arrays. the first array contains the string values you want to put into the type. You will also need the value associated with the each entry. The next array is the color mapping (i always set the color mapping to -1, which essentially means you dont care about it). Finally, you need the mapping to the previous type. This array contains the index of the entry in the previous type and -1 if it is a new value. This one can get tricky and is discussed in more detail in the referenced posts. For your example the arrays would look like this.
 

string stringVals[] = ["x", "d", "z", "a", "b", "c"] 
int ordinals[] = [0, 1, 2, 3, 4, 5]
int colors[] = [-1, -1, -1, -1, -1, -1]
int mapping[] = [0, -1, 2, 3, 4, 5]

 


once you have these arrays built, you call the modify command. The whole picture would look something like this

AttrType at = find(Module mod, string typeName)
if (null at) {
    // type not found
}
string errMsg = null
 
string stringVals[] = ["x", "d", "z", "a", "b", "c"] 
int ordinals[] = [0, 1, 2, 3, 4, 5]
int colors[] = [-1, -1, -1, -1, -1, -1]
int mapping[] = [0, -1, 2, 3, 4, 5]
 
 
at = modify(at, typeName, stringVals, ordinals, colors, mapping, errMsg)
 
// if there was an error with the modify, print the message
if (!null errMsg){
    print errMsg"\n"
}



I didnt have time to really check it or look too much up so a second check on this (cough louie) would be nice.
Hope this helps,

-Adam



 

As of when do I comment on other folks DXL? lol

The user needs to decide when an object has selected "y" and that option is no longer available, whether the value should be lost or if it should be replaced with "d".

int mapping[] = 0, -1, 2, 3, 4, 5

The "-1" means the 2nd enum now "d" is NOT mapped to anything, specifically not the previous "y", and all "y" object-values will be lost.

int mapping[] = 0, 1, 2, 3, 4, 5

The "1" means the 2nd enum now "d" is mapped to the previous 2nd enum "y", and any obj-value of "y" will become "d". I suspect this is what they want.

Once you do this you need to re-display all the objects:

for obj in entire mod do
{  if (!isDeleted(obj))     // delete this if not running v9201.
     obj.NameAttr = obj.NameAttr
}


Need a wrapper for this, opening the module Edit and saving and closing.

 

 

  • Louie


On a general note, I'd like to emphasize that all these arrays are declared at the same exact size of the new set of enumerations, and the mapping array contains value pointing to the old set. So if you are reducing the number of enumerations its possible the mapping value can be larger than the mapping array.

 

 

Re: Changing Enumerated Values
SystemAdmin - Mon Sep 19 17:57:21 EDT 2011

llandale - Mon Sep 19 17:22:42 EDT 2011

As of when do I comment on other folks DXL? lol

The user needs to decide when an object has selected "y" and that option is no longer available, whether the value should be lost or if it should be replaced with "d".

int mapping[] = 0, -1, 2, 3, 4, 5

The "-1" means the 2nd enum now "d" is NOT mapped to anything, specifically not the previous "y", and all "y" object-values will be lost.

int mapping[] = 0, 1, 2, 3, 4, 5

The "1" means the 2nd enum now "d" is mapped to the previous 2nd enum "y", and any obj-value of "y" will become "d". I suspect this is what they want.

Once you do this you need to re-display all the objects:

for obj in entire mod do
{  if (!isDeleted(obj))     // delete this if not running v9201.
     obj.NameAttr = obj.NameAttr
}


Need a wrapper for this, opening the module Edit and saving and closing.

 

 

  • Louie


On a general note, I'd like to emphasize that all these arrays are declared at the same exact size of the new set of enumerations, and the mapping array contains value pointing to the old set. So if you are reducing the number of enumerations its possible the mapping value can be larger than the mapping array.

 

 

hahaha does the variable name "prulhiere_fiasco" ring any bells? you were able to find the error in that debacle so i figured youd spot the error i inevitably posted up there.
"The "1" means the 2nd enum now "d" is mapped to the previous 2nd enum "y", and any obj-value of "y" will become "d"." - I was under the impression that it would only remove the "y" rather than reassign to "d"...see, good thing you posted, as this bit of information is likely to prevent a situation where i start crashing doors and look to you for help...again.
-Adam

Re: Changing Enumerated Values
llandale - Mon Sep 19 19:31:43 EDT 2011

SystemAdmin - Mon Sep 19 17:57:21 EDT 2011
hahaha does the variable name "prulhiere_fiasco" ring any bells? you were able to find the error in that debacle so i figured youd spot the error i inevitably posted up there.
"The "1" means the 2nd enum now "d" is mapped to the previous 2nd enum "y", and any obj-value of "y" will become "d"." - I was under the impression that it would only remove the "y" rather than reassign to "d"...see, good thing you posted, as this bit of information is likely to prevent a situation where i start crashing doors and look to you for help...again.
-Adam

Sorry about that reference, sometimes I type what I'm thinking and sometimes I think what's untrue but amusing .. to me.

The code wasn't going to crash DOORS, just lose the previous "y" values. If the arrays don't all have the same size and all filled in, THAT would crash doors.

Lets say you are changing enums:
Before: "Low", "Medium", "High", and "Super"
After : "None", "Manageable", "Average", "High", "Critical"

You want Low to become Manageable, Medium to become Average, High to become Critical (taking note there is also a new "High" value), and Super to be erased, your mapping would be this:

-1, 0, 1, -1, 2

Confusing yes, helps to line up your arrays into a nice looking table.

"None", "Manageable", "Average", "High", "Critical"
-1,     0,        1,       -1       2


Helps me anyway.

-Louie

Well actually, I define the arrays at the correct size and then use a function to populate them:

 

void Init(int Index, string Value, int Ordinal, RealColor, iMapping)
{  Values[Index]   = Value
   Ordinals[Index] = Ordinal
   Colors[Index]   = RealColor
   Mapping[Index]  = iMapping
}  // end Init()
Init(0, "None",      0, -1, -1)
Init(1, "Manageable", 1, -1,  0)

 

Re: Changing Enumerated Values
SystemAdmin - Fri Sep 23 14:46:09 EDT 2011

llandale - Mon Sep 19 19:31:43 EDT 2011

Sorry about that reference, sometimes I type what I'm thinking and sometimes I think what's untrue but amusing .. to me.

The code wasn't going to crash DOORS, just lose the previous "y" values. If the arrays don't all have the same size and all filled in, THAT would crash doors.

Lets say you are changing enums:
Before: "Low", "Medium", "High", and "Super"
After : "None", "Manageable", "Average", "High", "Critical"

You want Low to become Manageable, Medium to become Average, High to become Critical (taking note there is also a new "High" value), and Super to be erased, your mapping would be this:

-1, 0, 1, -1, 2

Confusing yes, helps to line up your arrays into a nice looking table.

"None", "Manageable", "Average", "High", "Critical"
-1,     0,        1,       -1       2


Helps me anyway.

-Louie

Well actually, I define the arrays at the correct size and then use a function to populate them:

 

void Init(int Index, string Value, int Ordinal, RealColor, iMapping)
{  Values[Index]   = Value
   Ordinals[Index] = Ordinal
   Colors[Index]   = RealColor
   Mapping[Index]  = iMapping
}  // end Init()
Init(0, "None",      0, -1, -1)
Init(1, "Manageable", 1, -1,  0)

 

haha its all good...calling it a fiasco was probably a little too nice to be honest.
I like the idea of using a function to populate the arrays...I just might start to doing that.
-Adam

Re: Changing Enumerated Values
llandale - Fri Sep 23 14:47:48 EDT 2011

SystemAdmin - Fri Sep 23 14:46:09 EDT 2011
haha its all good...calling it a fiasco was probably a little too nice to be honest.
I like the idea of using a function to populate the arrays...I just might start to doing that.
-Adam

Makes it easier for me to visualize what I'm doing.

Re: Changing Enumerated Values
vppatel - Mon Sep 26 10:56:59 EDT 2011

Thanks for the help, was able to complete the update to the values.